package com.test.practice.socket.tcp.file;

import com.test.practice.socket.InetAddressDemo;
import lombok.Cleanup;

import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * @Description: =======================
 * @Author: Jovi
 * =======================
 * @Date: Created in 2023-02-10
 * =======================
 * @Version: 1.1.2.0
 */
public class TcpFileClientDemo {

    public static void main(String[] args) throws Exception {
        @Cleanup Socket socket = new Socket(InetAddress.getByName("127.0.0.1"), 6666);

        @Cleanup OutputStream os = socket.getOutputStream();

        @Cleanup FileInputStream fis = new FileInputStream("1.png");

        byte[] datas = new byte[1024];

        int len;
        while ((len = fis.read(datas)) != -1) {
            os.write(datas, 0, len);
        }

    }
}
